﻿using System;
using Messages;
using Rhino.ServiceBus;
using Rhino.ServiceBus.Hosting;
using Utils_Rhino;

namespace Server_Rhino
{
    class Program
    {
        static void Main(string[] args)
        {
            Queues.PrepareQueue("server_rhino");

            Console.WriteLine("Listening for messages to intercept..");

            var host = new DefaultHost();
            host.Start<BootStrapper>();

            Console.ReadLine();
        }
    }

    public class MessageInterceptAndResponse : ConsumerOf<Message_Type1>
    {
        private readonly IServiceBus _serviceBus;

        public MessageInterceptAndResponse(IServiceBus serviceBus)
        {
            _serviceBus = serviceBus;
        }

        public void Consume(Message_Type1 msg)
        {
            Console.WriteLine("Message intercepted: " + msg.Text);

            Console.WriteLine("Replying...");

            _serviceBus.Reply(new Message_Type2
            {
                Text = msg.Text + ". Adding something new to the message"
            });
        }
    }
}
